//
//  WKCellToolbar.m
//  WKDemo
//
//  Created by wangzhaohui-Mac on 14-8-6.
//  Copyright (c) 2014年 com.app. All rights reserved.
//

#import "WKCellToolbar.h"

@implementation WKCellToolbar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //清除背景颜色
        self.backgroundColor = [UIColor clearColor];
        
        //添加按钮
        [self setupBtnWithIcon:@"mainCellDing" title:@"转发"];
        [self setupBtnWithIcon:@"statusdetail_icon_comment" title:@"评论"];
        [self setupBtnWithIcon:@"statusdetail_icon_like" title:@"赞"];
    }
    return self;
}

/**
 *  添加按钮
 *
 *  @param icon  按钮图标
 *  @param title 按钮文字
 */
- (UIButton *)setupBtnWithIcon:(NSString *)icon title:(NSString *)title
{
    //创建按钮
    UIButton *btn = [[UIButton alloc] init];
    
    [btn setImage:[UIImage imageWithName:icon] forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:13];
    
    //设置间距
    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    //添加按钮到工具条上
    [self addSubview:btn];
    
    return btn;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //设置按钮的frame
    int btnCount = self.subviews.count;
    CGFloat btnW = self.width / btnCount;
    CGFloat btnH = self.height;
    for (int i = 0; i < btnCount; i++) {
        CGFloat btnX = i * btnW;
        CGFloat btnY = 0;
        UIButton *btn = self.subviews[i];
        btn.frame = CGRectMake(btnX, btnY, btnW, btnH);
    }
}

- (void)drawRect:(CGRect)rect
{
    
    //将背景图片绘制到工具条上
    [[UIImage resizeImageWithName:@"statusdetail_toolbar_background"] drawInRect:rect];
}

@end
